<?php
/////////////////////////////////////////////////////////////////////////////
// FleaPHP Framework
//
// Copyright (c) 2005 - 2008 QeeYuan China Inc. (http://www.qeeyuan.com)
//
// 许可协议，请查看源代码中附带的 LICENSE.txt 文件，
// 或者访问 http://www.fleaphp.org/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * 定义 Controller_BoArticles 类
 *
 * @copyright Copyright (c) 2005 - 2008 QeeYuan China Inc. (http://www.qeeyuan.com)
 * @author 起源科技 (www.qeeyuan.com)
 * @package Example
 * @subpackage SHOP
 * @version $Id: BoArticles.php 972 2007-10-09 20:56:54Z qeeyuan $
 */

// {{{ includes
FLEA::loadClass('Controller_BoBase');
// }}}

/**
 * Controller_BoArticles 提供了操作产品信息的后台界面功能
 *
 * @package Example
 * @subpackage SHOP
 * @author 起源科技 (www.qeeyuan.com)
 * @version 1.0
 */
class Controller_BoConfig extends Controller_BoBase
{
	
	/**
     * @var Model_Users
     */
    var $_tableConfig;
    var $dbo;
	/**
     * 构造函数
     *
     * @return Controller_BoUsers
     */
    function Controller_BoConfig() {
        parent::Controller_BoBase();
        $this->access = CLASSES_ADMIN;
        //用户角色权限控制
        if(!$this->checkDispatcher($this->access)){
            redirect(url('BoDashboard','ErrorIn'));
        }
        $this->_tableConfig =& FLEA::getSingleton('Table_Config');
        $this->dbo = &FLEA::getDBO();
    }
    
    /**
     * 显示列表
     */
    function actionIndex() {
		if($_REQUEST['name'])$field[] = "name like '%".$_REQUEST['name']."%'";		
        $page = isset($_GET['page']) ? (int)$_GET['page'] : 0;
        FLEA::loadClass('FLEA_Helper_Pager');
        $pager =& new FLEA_Helper_Pager($this->_tableConfig, $page, 10, $field);
        $pk = $this->_tableConfig->primaryKey;
        $rowset = $pager->findAll("*",$field);
        $this->_setBack();
        $total = count($this->_tableConfig->findAll());
        //dump($this->dbo->log);
        include(TPL_DIR . '/BoConfigList.php');
    }
    //新建
    function actionCreate(){
    	include(TPL_DIR . '/BoConfigEdit.php');
    }
    //删除
    function actionDelete(){
    	$eid = $_GET['id'];
    	if($eid)$result = $this->_tableConfig->removeByPkv($eid,false);
    	if($result)$msg = '删除成功';
    	else $msg = '删除失败';
    	echo '<script language="javascript" type="text/javascript">alert("'.$msg.'");window.location.href="index.php?controller=BoConfig&action=index"</script>';
    }
    //编辑
    function actionEdit(){
    	$eid = $_GET['id'];
    	if($eid)$result = $this->_tableConfig->find($eid);
		if($result)include(TPL_DIR . '/BoConfigEdit.php');
    	else '<script language="javascript" type="text/javascript">alert("参数错误");window.location.href="index.php?controller=BoConfig&action=index"</script>';
    }
    //保存
    function actionSave(){
    	$name = $_POST['name'];
    	$value = $_POST['value'];
    	$comment = $_POST['comment'];
    	$id = $_POST['id'];
    	$data = array();
    	if($id)$data['id'] = $id;
    	if($name)$data['name'] = $name;
    	$data['value'] = $value;
    	if($comment)$data['comment'] = $comment;
    	$result = $this->_tableConfig->save($data);
    	if($result)$msg = '保存成功';
    	else $msg = '保存失败';
    	echo '<script language="javascript" type="text/javascript">alert("'.$msg.'");window.location.href="index.php?controller=BoConfig&action=index"</script>';
    }
}